import Vue from 'vue'
import Router from 'vue-router'
import getWeb3 from '../utils/getWeb3'


Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'index',
      component: () => import('../views/index.vue')
    },
    {
      path: '/card/:id',
      name: 'card',
      component: () => import('../views/card.vue')
    },
    {
      path: '/vindicate',
      name: 'post',
      component: () => import('../views/vindicate.vue')
    },
    {
      path: '/wall',
      name: 'wall',
      component: () => import('../views/wall.vue')
    },
    {
      path: '/search',
      name: 'search',
      component: () => import('../views/search.vue')
    },
    {
      path: '/person',
      name: 'person',
      component: () => import('../views/person.vue')
    }
  ]
})

//添加导航守卫
router.beforeEach((to, form, next) => {
  //访问下面路由直接放行
  if (to.path.startsWith("/card/") || to.path == "/wall" || to.path == "/") {
    next()
  } else {
    const signature = localStorage.getItem("signature")
    if (signature == "" || signature == null || signature == '') {
      next("/")
    } else {
      next()
    }
  }
})

export default router
